/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.awt.Toolkit;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Vincent
 */
public class DialogueChargerSimulation extends javax.swing.JFrame {
    SimIHM ihm;
    ResultSet rs;
    MenuPrincipal menu;
    /**
     * Creates new form DialogueChargerSimulation
     */
    public DialogueChargerSimulation(SimIHM ihm, MenuPrincipal menu) {
        this.ihm = ihm;
        this.menu = menu;
        String[] noms;
        initComponents();
        
        //Centre la fenetre
        setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/2-getWidth()/2,
                Toolkit.getDefaultToolkit().getScreenSize().height/2-getHeight()/2);
        
        //Charge les noms des simulations existantes dans la combobox
        if (ihm!=null){
            noms = ihm.menu.co.nomSimulations();
        }else{
            noms = menu.co.nomSimulations();
        }
        
        for (String i : noms){
            if (i==null) {continue;}
            //System.out.println(i);
            comboBoxSimulation.addItem(i);
        }
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        comboBoxSimulation = new javax.swing.JComboBox();
        labelChargement = new javax.swing.JLabel();
        boutonAnnuler = new javax.swing.JButton();
        boutonValiderChargement = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        labelChargement.setText("Choisir simulation :");

        boutonAnnuler.setText("Annuler");
        boutonAnnuler.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                boutonAnnulerMouseReleased(evt);
            }
        });

        boutonValiderChargement.setText("OK");
        boutonValiderChargement.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                boutonValiderChargementMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(boutonValiderChargement, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boutonAnnuler))
                    .addComponent(labelChargement)
                    .addComponent(comboBoxSimulation, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelChargement)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboBoxSimulation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(boutonAnnuler)
                    .addComponent(boutonValiderChargement))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void boutonValiderChargementMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boutonValiderChargementMouseReleased
        // TODO add your handling code here:
        //System.out.println(comboBoxSimulation.getSelectedItem().toString());
        if (ihm!=null){
            new SimIHM(ihm.menu, 0, comboBoxSimulation.getSelectedItem().toString()).setVisible(true);
            ihm.dispose();
            ihm.sim.dispose();
        } else {
            new SimIHM(menu, 0, comboBoxSimulation.getSelectedItem().toString()).setVisible(true);
        }
        dispose();
    }//GEN-LAST:event_boutonValiderChargementMouseReleased

    private void boutonAnnulerMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boutonAnnulerMouseReleased
        // TODO add your handling code here:
        if (ihm!=null) {
            ihm.setVisible(true);
        } else {
            menu.setVisible(true);
        }
        dispose();
    }//GEN-LAST:event_boutonAnnulerMouseReleased

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boutonAnnuler;
    private javax.swing.JButton boutonValiderChargement;
    private javax.swing.JComboBox comboBoxSimulation;
    private javax.swing.JLabel labelChargement;
    // End of variables declaration//GEN-END:variables
}
